<template>

  <!--

    对话框（2）：选择物料

    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectPart.title"
             :visible.sync="dialog_selectPart.visible"
             width="1100px">

    <!-- 检索条件 -->
    <el-form :model="dialog_selectPart.queryParams"
             :inline="true" v-show="dialog_selectPart.showSearch" label-width="68px">

      <!-- 物料名称 -->
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="dialog_selectPart.queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          size="small"
          @keyup.enter.native="getList_parts"
        />
      </el-form-item>

      <!-- 物料编码 -->
      <el-form-item label="物料编码" prop="itemNum">
        <el-input
          v-model="dialog_selectPart.queryParams.itemNum"
          placeholder="请输入物料编码"
          clearable
          size="small"
          @keyup.enter.native="getList_parts"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_parts">搜索</el-button>
      </el-form-item>

    </el-form>


    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="dialog_selectPart.partList"
      row-key="itemUuid"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="物料名称" align="center" prop="itemName" />
      <el-table-column label="物料编码" align="center" prop="itemNum" width="160"/>

      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="success" plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectItem_done(scope.row)"
          ><span> 选择</span></el-button>
        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="dialog_selectPart.total>0"
      :total="dialog_selectPart.total"
      :page.sync="dialog_selectPart.queryParams.pageNum"
      :limit.sync="dialog_selectPart.queryParams.pageSize"
      @pagination="getList_parts"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectPart">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
import {listProcess} from "@/api/mes/process";
export default {
  dicts: ['sys_normal_disable'],
  props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  },
  data() {
    return {

      dialog_selectPart: {
        visible: false,
        showSearch: true,
        title: "请选择零件",
        total: 0,
        partList: [],
        queryParams:{
          itemName: null,
        }
      },

      // 遮罩层
      loading: true,

      // 遮罩层
      visible: false,
      // 选中数组值
      userIds: [],
      // 总条数
      total: 0,
      // 未授权用户数据
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleId: undefined,
        userName: undefined,
        phonenumber: undefined
      },
      selectedUser: {
        id: null,
        nickName: null,
        userName: null
      }
    };
  },
  methods: {


    /** 读取列表：物料 */
    getList_parts() {
      this.loading = true;
      console.log(this.form.orderDetailItemUuid)
      listProcess(this.dialog_selectPart.queryParams).then(response => {
        console.log( response )
        this.dialog_selectPart.partList = response.rows;
        this.dialog_selectPart.total = response.total;
        this.loading = false;
      });
    },



    // 完成：选择物料
    selectPart_done(user) {
      this.dialog_selectPart.visible = false;
      this.$emit("ok", user );
      console.log( user )
    },


    // 对话框：显示 - 选择物料
    dialog_show_selectPart() {
      this.getList_parts()
      this.dialog_selectPart.visible = true;
      this.dialog_selectPart.title = "选择零件";
    },

    // 对话框：隐藏 - 选择物料
    dialog_hide_selectPart() {
      this.dialog_selectPart.visible = false;
    },

    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
